package com.yang.controller;

import com.yang.service.SelectInfomationService;
import org.jboss.logging.Logger;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
public class SelectInfomationController {

    public static Logger logger = Logger.getLogger(SelectInfomationController.class);

    @Resource
    SelectInfomationService selectInfomationService;

    /**
     * 信息查询
     * @param selectwhich
     * @param guestStatus
     * @param selectName
     * @return
     */
    @RequestMapping(produces = "application/json;charset=UTF-8",value = "admin/selectData",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> selectInfomatino(String selectwhich,String guestStatus,String selectName){
        Map<String,Object> map = new HashMap<String, Object>();
        if(selectwhich==null||selectwhich.equals("")||selectName==null||selectName.equals("")||guestStatus == null || guestStatus.equals("")){
            map.put("status","error");
            map.put("info","输入存在空值！");
            logger.error("输人空置");
            return map;
        }
        map = selectInfomationService.selectInformation(selectwhich,guestStatus,selectName);
        return map;
    }

    /**
     * 在住旅客修改查询
     * @param roomNum
     * @param name
     * @return
     */
    @RequestMapping(produces = "application/json;charset=UTF-8",value = "admin/selectModification",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> selectModification(String roomNum,String name){
        Map<String,Object> map = new HashMap<String, Object>();
        if(roomNum == null ||roomNum.equals("") || name == null || name.equals("")){
            map.put("status","error");
            map.put("info","输入存在空值！");
            logger.error("输人空值");
            return map;
        }
        map = selectInfomationService.selectModification(roomNum, name);
        return map;
    }

    /**
     * 在住旅客信息修改
     * @param id
     * @param name
     * @param tel
     * @param identification
     * @return
     */
    @RequestMapping (produces = "application/json;charset=UTF-8",value = "admin/modification",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> modification(String id,String name,String tel,String identification){
        Map<String ,Object> map = new HashMap<String, Object>();
        if(id == null ||id.equals("")||tel==null||tel.equals("")||identification == null||identification.equals("")||name == null||name.equals("")){
            map.put("status","error");
            map.put("info","输入存在空值");
            logger.error("输入存在空值");
            return map;
        }
        logger.info("id = "+id+" name = "+name+" tel = "+tel+"  identification ="+identification);
        long idLong = Long.parseLong(id);
        map = selectInfomationService.Modification(idLong,name,tel,identification);
        return map;
    }
}


















